//
//  AppDelegate+RootController.m
//  JF_New_DYKT
//
//  Created by 陈雷 on 2017/8/22.
//  Copyright © 2017年 陈雷. All rights reserved.
//

#import "AppDelegate+RootController.h"
#import "HomePageController.h"
#import "TutorController.h"
#import "LiveController.h"
#import "MIneController.h"
#import "MessageControllerViewController.h"
#import "FirstGuideController.h"


@implementation AppDelegate (RootController)


- (void)setTabbarController
{

    HomePageController *homeVc = [[HomePageController alloc]init];
    BaseNavController *homeNav = [[BaseNavController alloc]initWithRootViewController:homeVc];
    
    TutorController *tutorVc = [[TutorController alloc]init];
    BaseNavController *tutorNav = [[BaseNavController alloc]initWithRootViewController:tutorVc];
    
    LiveController *liveVc = [[LiveController alloc]init];
    BaseNavController *liveNav = [[BaseNavController alloc]initWithRootViewController:liveVc];
    
    MessageControllerViewController *messageVc = [[MessageControllerViewController alloc]init];
    BaseNavController *messageNav = [[BaseNavController alloc]initWithRootViewController:messageVc];
    
    MIneController *mineVc = [[MIneController alloc]init];
    BaseNavController *mineNav = [[BaseNavController alloc]initWithRootViewController:mineVc];
    
    BaseTabbarController *tabBarController = [[BaseTabbarController alloc] init];

    
#pragma mark- 控制按钮的大小
//    CGSize indicatorImageSize = CGSizeMake(KSCreenWidth/5+20,46+20);
//    tabBarController.tabBar.selectionIndicatorImage=[self drawTabBarItemBackgroundUmageWithSize:indicatorImageSize];

    
    homeVc.tabBarItem.title = @"首页";
    homeVc.tabBarItem.image = [[UIImage imageNamed:@"JFGGhome"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    homeVc.tabBarItem.selectedImage = [[UIImage imageNamed:@"JFGGhome-green"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    tutorVc.tabBarItem.title = @"家庭导师";
    tutorVc.tabBarItem.image = [[UIImage imageNamed:@"JFGGteacher"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tutorVc.tabBarItem.selectedImage = [[UIImage imageNamed:@"JFGGteacher-green"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    liveVc.tabBarItem.title = @"直播";
    liveVc.tabBarItem.image = [[UIImage imageNamed:@"JFGGlive"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    liveVc.tabBarItem.selectedImage = [[UIImage imageNamed:@"JFGGlive-green"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    messageVc.tabBarItem.title = @"消息";
    messageVc.tabBarItem.image = [[UIImage imageNamed:@"JFGGfriend"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    messageVc.tabBarItem.selectedImage = [[UIImage imageNamed:@"JFGGfriend-green"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    mineVc.tabBarItem.title = @"我的";
    mineVc.tabBarItem.image = [[UIImage imageNamed:@"JFGGmy"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    mineVc.tabBarItem.selectedImage = [[UIImage imageNamed:@"JFGGmy-green"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    [tabBarController setViewControllers:@[homeNav,tutorNav,liveNav,messageNav,mineNav]];
    
    //字体大小，颜色（未被选中时）
    [[UITabBarItem appearance]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor lightGrayColor],NSForegroundColorAttributeName,[UIFont fontWithName:@"Helvetica"size:10.0f],NSFontAttributeName,nil]forState:UIControlStateNormal];
    
    //字体大小，颜色（被选中时）
    [[UITabBarItem appearance]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHexString:@"1cda9f"],NSForegroundColorAttributeName,[UIFont fontWithName:@"Helvetica" size:10.0f],NSFontAttributeName,nil]forState:UIControlStateSelected];
    
    if ([[UserDefaults objectForKey:@"firstLogin"] isEqualToString:@"haveUse"]) {
        self.window.rootViewController = tabBarController;
    }else{
        FirstGuideController *firstGuideVc = [[FirstGuideController alloc]init];
        self.window.rootViewController = firstGuideVc;
    }
    
}

#pragma mark- 设置window
- (void)configKeyWindow{
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    self.window.backgroundColor = [UIColor whiteColor];
    
    [self.window makeKeyAndVisible];
}


//绘制图片
-(UIImage*)drawTabBarItemBackgroundUmageWithSize:(CGSize)size

{
    //开始图形上下文
    
    UIGraphicsBeginImageContext(size);
    
    //获得图形上下文
    
    CGContextRef ctx=UIGraphicsGetCurrentContext();
    
    CGContextSetRGBFillColor(ctx,1,1,1,1);
    
    CGContextFillRect(ctx,CGRectMake(5,0,size.width,size.height));
    
    CGRect rect=CGRectMake(0,0,size.width,size.height);
    
    CGContextAddEllipseInRect(ctx, rect);
    
    CGContextClip(ctx);
    
    UIImage*image=UIGraphicsGetImageFromCurrentImageContext();
    
    [image drawInRect:rect];
    
    UIGraphicsEndImageContext();
    
    return image;
    
}


- (void)createLoadingScrollView
{
    //引导页实例
}


@end
